from django import forms
from django.core import validators
from django.contrib.auth.models import User
from CostCalc.HomePage.models import EventProfile, EventExpenseProfile
import datetime
 
 
class RegistrationForm(forms.Form):
    username = forms.CharField(label="Username" )
    email = forms.EmailField(label="Email Address"  )
    password = forms.CharField( widget=forms.PasswordInput, label="Password" )    

    def save(self, new_data):
        u = User.objects.create_user(new_data['username'],
                                     new_data['email'],
                                     new_data['password'])
        u.is_active = False
        u.save()
        return u

class CreateEventForm(forms.Form):
    eventStartDate = forms.CharField(max_length = 32)
    eventEndDate= forms.CharField(max_length = 32)
    eventName = forms.CharField(max_length = 32)
    
    def save(self, new_data):
        TP = EventProfile(eventStartDate = new_data['eventStartDate'],
                            eventEndDate = new_data['eventEndDate'],
                            eventName = new_data['eventName'])
        TP.save()
        return TP
    
    
class EventExpenseForm(forms.Form):
    #expenseOwner = forms.CharField(label="Person Owed Money", choices=TITLE_CHOICES)
    expenseName = forms.CharField(label="Expense Name" )
    expenseAmount = forms.FloatField(label="Expense Amount")
    expenseDate = forms.DateField(label = "Date of Expense")
    
    def save(self, new_data, userId, Event):
        Expense = EventExpenseProfile(expenseName = new_data['expenseName'],
                                          expenseAmount = new_data['expenseAmount'],
                                          expenseDate = new_data['expenseDate'],
                                          expenseAddedDate = new_data['expenseDate'],
                                          expenseOwner_id = userId,
                                          expenseEvent = Event)
        
        Expense.save()
        return Expense
    
class SetPeopleOnEventForm(forms.Form):
    People_Choices = []
    
    


